﻿using System;
using System.Data;

namespace DAL
{
    public static class DalOrderServicesMaintain
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetSell(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_SellService_Get");
        }
        public static DataTable GetSellDetail(string keywords, int Id_Sell)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            Cls.AddParameter("@ID_Sell", Id_Sell);
            return Cls.GetData("sp_SellService_Get_Detail");
        }
        public static DataTable GetOrderServicesMaintain(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Order_Services_Maintain_Get");
        }
        public static DataTable GetOrderServicesMaintainFillter(string DateBegin,string DateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@DateBegin", DateBegin);
            Cls.AddParameter("@EndBegin", DateEnd);
            return Cls.GetData("sp_Order_Services_Maintain_Get_Fillter");
        }
        public static DataTable GetOrderServicesMaintainEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", id);
            return Cls.GetData("sp_Order_Services_Maintain_Get_Edit");
        }
        public static DataTable GetOrderServicesMaintainEditGrid(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", id);
            return Cls.GetData("sp_Order_Services_Maintain_Get_Edit_Grid");
        }
        public static DataTable GetOrderServicesMaintainDetailTemp(int Users_Id, int Flag)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", Users_Id);
            Cls.AddParameter("@Flag", Flag);
            return Cls.GetData("sp_Order_Services_Maintain_Get_Tmp");
        }
        public static DataTable GetSellSum(int ? Maintain_ID, int ? Users_Id, int Flag)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", Maintain_ID);
            Cls.AddParameter("@Users_Id", Users_Id);
            Cls.AddParameter("@Flag", Flag);
            return Cls.GetData("sp_Order_Services_Maintain_Detail_Sum");
        }
        public static bool GetOrderServicesMaintainCheckReview(EtOrderServicesMaintain obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", obj.Maintain_ID);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_SellService_Get_CheckReview", "@Msg");
            return true;
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(EtOrderServicesMaintain obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Order_Sell_Id", obj.Order_Sell_Id);
            Cls.AddParameter("@Maintain_Code", obj.Maintain_Code);
            Cls.AddParameter("@Maintain_DateBegin", obj.Maintain_DateBegin);
            Cls.AddParameter("@Maintain_TaxCode", obj.Maintain_TaxCode);
            Cls.AddParameter("@IsActive", obj.IsActive);
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            Cls.AddParameter("@Note", obj.Note);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Insert");
        }
        public static bool Update(EtOrderServicesMaintain obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", obj.Maintain_ID);
            Cls.AddParameter("@Maintain_TaxCode", obj.Maintain_TaxCode);
            Cls.AddParameter("@Note", obj.Note);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Update");
        }
        public static bool Delete(EtOrderServicesMaintain obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", obj.Maintain_ID);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Delete");
        }
        public static bool InsertDetail(EtOrderServicesMaintainDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", obj.Maintain_ID);
            Cls.AddParameter("@Order_Sell_Detail_Id", obj.Order_Sell_Detail_Id);
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            Cls.AddParameter("@Flag", obj.Flag);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Detail_Insert");
        }
        public static bool UpdateDetail(EtOrderServicesMaintainDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_Detail_ID", obj.Maintain_Detail_ID);
            Cls.AddParameter("@Maintain_DateEnd", obj.Maintain_DateEnd);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Detail_Update");
        }
        public static bool DeleteDetail(EtOrderServicesMaintainDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_Detail_ID", obj.Maintain_Detail_ID);
            Cls.AddParameter("@Flag", obj.Flag);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Detail_Delete");
        }
        public static bool DeleteAdd(EtOrderServicesMaintainDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            Cls.AddParameter("@Flag", obj.Flag);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Detail_Delete_Add");
        }
        public static bool Review(EtOrderServicesMaintain obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Maintain_ID", obj.Maintain_ID);
            Cls.AddParameter("@Review", obj.Review);
            Cls.AddParameter("@Uses_Review", obj.Uses_Review);
            return Cls.ExecuteNonQuery("sp_Order_Services_Maintain_Review");
        }
        #endregion
    }

    public class EtOrderServicesMaintain
    {
        public int ? Maintain_ID { get; set; }
        public int ? Order_Sell_Id { get; set; }
        public string Maintain_Code { get; set; }
        public DateTime Maintain_DateBegin { get; set; }
        public string Maintain_TaxCode { get; set; }
        public bool IsActive { get; set; }
        public int ? Users_Id { get; set; }
        public string Note { get; set; }
        public int Msg { get; set; }
        public bool Review { get; set; }
        public int Uses_Review { get; set; }
    }
    public class EtOrderServicesMaintainDetail
    {
        public int ? Maintain_Detail_ID { get; set; }
        public int ? Maintain_ID { get; set; }
        public int ? Order_Sell_Detail_Id { get; set; }
        public string Maintain_Code { get; set; }
        public DateTime Maintain_DateBegin { get; set; }
        public DateTime Maintain_DateEnd { get; set; }
        public string Maintain_TaxCode { get; set; }
        public int ? Flag { get; set; }
        public int ? Users_Id { get; set; }
    }
}